package tests;

import common.utilsEdge;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;
import java.time.Duration;

public class LoginTestEdge extends utilsEdge {
    public static final String url="http://127.0.0.1:8080/login.html";
    public LoginTestEdge() {
        super(url);
    }
    public void LoginSuc() throws InterruptedException {

        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#username")).sendKeys("hanmeimei1");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456789");
        driver.findElement(By.cssSelector("#submit")).click();



        Alert alert=driver.switchTo().alert();
        alert.accept();

        driver.navigate().back();
        String title = driver.getTitle();
        assert title.equals("登录");

    }

    public void LoginFail() throws InterruptedException, IOException {
        WebDriverWait wait=new WebDriverWait(driver, Duration.ofSeconds(3));

        //账号密码都不对
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456789");

        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert=driver.switchTo().alert();
        alert.accept();

        //账号对密码不对
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        driver.findElement(By.cssSelector("#username")).sendKeys("hanmeimei1");
        driver.findElement(By.cssSelector("#password")).sendKeys("1234");

        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();


        //账号不对密码对
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        driver.findElement(By.cssSelector("#username")).sendKeys("hanmeimei");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456789");

        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();


        //账号包含特殊字符
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        driver.findElement(By.cssSelector("#username")).sendKeys("#$@!@");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456789");

        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();


        //密码包含特殊字符
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#username")).sendKeys("hanmeimei1");
        driver.findElement(By.cssSelector("#password")).sendKeys("@^%%^%^&#");
        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();


        //账号为空是否可以登录
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        driver.findElement(By.cssSelector("#password")).sendKeys("123456789");

        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();

        //密码为空是否可以登录
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");

        driver.findElement(By.cssSelector("#submit")).click();
        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();

        //账号超出字符限制是否可以登录
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#username")).sendKeys("hanmeimei1dasjkhdajdhkladjlkadjlkadadadadaddadadadadadasdadklahjdka");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456789");
        driver.findElement(By.cssSelector("#submit")).click();

        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();

        //密码超出字符限制是否可以登录
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#username")).sendKeys("hanmeimei1");
        driver.findElement(By.cssSelector("#password")).sendKeys("1234567893654486635885457855474455241445552144444");
        driver.findElement(By.cssSelector("#submit")).click();

        wait.until(ExpectedConditions.alertIsPresent());
        alert=driver.switchTo().alert();
        alert.accept();

    }
}
